import { Options } from '../entity/Options';

export function getProcessArgIn<T extends string>(value: string, values: T[]): T | undefined {
  if (!value || !values || values.length === 0) return undefined;
  for (let v of values) {
    if (v === value) return v;
  }
  return undefined;
}

export function getProcessArg(key: string): string | undefined {
  let matchResult = process.argv.filter(s => s.match(`--${key}=`));
  if (!matchResult || matchResult.length === 0) return undefined;
  return matchResult[0].match(`--${key}=(.*)`)?.[1];
}

export function getZipFullName(options: Options) {
  return getZipName(options) + '.' + getExtName(options);
}

export function getZipName(options: Options) {
  return `nwjs${options.flavor === 'sdk' ? '-sdk' : ''}-v${options.version}-${options.platform}-${options.arch}`;
}

export function getExtName(options: Options) {
  return options.platform === 'linux' ? 'tar.gz' : 'zip';
}
